package com.ftwj.controller;

import com.ftwj.base.SystemConsts;
import com.ftwj.entity.dict.AddDictDTO;
import com.ftwj.entity.dict.DictDTO;
import com.ftwj.service.DictInfoService;
import com.ftwj.utils.result.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * ┌───┐   ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┐
 * │Esc│   │ F1│ F2│ F3│ F4│ │ F5│ F6│ F7│ F8│ │ F9│F10│F11│F12│ │P/S│S L│P/B│  ┌┐    ┌┐    ┌┐
 * └───┘   └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┘  └┘    └┘    └┘
 * ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───────┐ ┌───┬───┬───┐ ┌───┬───┬───┬───┐
 * │~ `│! 1│@ 2│# 3│$ 4│% 5│^ 6│& 7│* 8│( 9│) 0│_ -│+ =│ BacSp │ │Ins│Hom│PUp│ │N L│ / │ * │ - │
 * ├───┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─────┤ ├───┼───┼───┤ ├───┼───┼───┼───┤
 * │ Tab │ Q │ W │ E │ R │ T │ Y │ U │ I │ O │ P │{ [│} ]│ | \ │ │Del│End│PDn│ │ 7 │ 8 │ 9 │   │
 * ├─────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴─────┤ └───┴───┴───┘ ├───┼───┼───┤ + │
 * │ Caps │ A │ S │ D │ F │ G │ H │ J │ K │ L │: ;│" '│ Enter  │               │ 4 │ 5 │ 6 │   │
 * ├──────┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴────────┤     ┌───┐     ├───┼───┼───┼───┤
 * │ Shift  │ Z │ X │ C │ V │ B │ N │ M │< ,│> .│? /│  Shift   │     │ ↑ │     │ 1 │ 2 │ 3 │   │
 * ├─────┬──┴─┬─┴──┬┴───┴───┴───┴───┴───┴──┬┴───┼───┴┬────┬────┤ ┌───┼───┼───┐ ├───┴───┼───┤ E││
 * │ Ctrl│    │Alt │         Space         │ Alt│    │    │Ctrl│ │ ← │ ↓ │ → │ │   0   │ . │←─┘│
 * └─────┴────┴────┴───────────────────────┴────┴────┴────┴────┘ └───┴───┴───┘ └───────┴───┴───┘
 *
 * @Author Liu_xg
 * @Date 2024/6/27 17:54
 * @Description
 */
@Api(tags = "字典相关")
@Slf4j
@RestController
@RequestMapping("/UAS/platform/dict/api/")
public class DictController {


    @Autowired
    private DictInfoService service;


    @ApiOperation(value = "查询字典列表", notes = "查询字典列表")
    @PostMapping(value = "queryDictList")
    public ResultBean queryDictList(HttpServletRequest request,
                                           HttpServletResponse response,
                                           @RequestBody @Validated DictDTO dictDTO) {

        try {
            return service.queryDictList(request, response, dictDTO);
        } catch (Exception e) {
            log.error("error", e);
            return new ResultBean(SystemConsts.EXCEPTION_FAIL_CODE,
                    SystemConsts.XI_TONG_YI_CHANG_MSG, e.getMessage());
        }
    }

    @ApiOperation(value = "新增字典", notes = "新增字典")
    @PostMapping(value = "addDict")
    public ResultBean addDict(HttpServletRequest request,
                                         HttpServletResponse response,
                                         @RequestBody @Validated AddDictDTO addDictDTO) {

        try {
            return service.addDict(request, response, addDictDTO);
        } catch (Exception e) {
            log.error("error", e);
            return new ResultBean(SystemConsts.EXCEPTION_FAIL_CODE,
                    SystemConsts.XI_TONG_YI_CHANG_MSG, e.getMessage());
        }
    }

    @ApiOperation(value = "修改字典", notes = "修改字典")
    @PostMapping(value = "editDict")
    public ResultBean editDict(HttpServletRequest request,
                                          HttpServletResponse response,
                                          @RequestBody @Validated AddDictDTO addDictDTO) {

        try {
            return service.editDict(request, response, addDictDTO);
        } catch (Exception e) {
            log.error("error", e);
            return new ResultBean(SystemConsts.EXCEPTION_FAIL_CODE,
                    SystemConsts.XI_TONG_YI_CHANG_MSG, e.getMessage());
        }
    }


    @ApiOperation(value = "删除字典", notes = "删除字典")
    @PostMapping(value = "delDict")
    public ResultBean delDict(HttpServletRequest request,
                                         HttpServletResponse response,
                                         @RequestBody @Validated AddDictDTO addDictDTO) {

        try {
            return service.delDict(request, response, addDictDTO);
        } catch (Exception e) {
            log.error("error", e);
            return new ResultBean(SystemConsts.EXCEPTION_FAIL_CODE,
                    SystemConsts.XI_TONG_YI_CHANG_MSG, e.getMessage());
        }
    }

}
